<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
 <script type="text/babel">
    let root = document.getElementById('root')
    class Clock extends React.Component {
        constructor(props) {
            super(props)
            this.timer = null
            this.state = {date: new Date().toLocaleTimeString()}
        }
        componentDidMount() {
           
        }
        getInfo() {
            this.setState({date: new Date().toLocaleTimeString()})
        }
        render() {
            this.timer = setInterval(() => this.getInfo(),1000)
            if(!this.props.show) {
                clearInterval(this.timer)
                return null
            }
            return (
                <h3>{this.state.date}</h3>
            )
        }
    }
    class Change extends React.Component {
        constructor(props) {
            super(props)
            this.state = {show: true}
            this.changeState = this.changeState.bind(this)
        }
        changeState() {
            this.setState((state) => ({
                show: !state.show 
            }))
            
        }
        render() {
          return (
            <div>
                <Clock show={this.state.show}/>
                <button onClick={this.changeState}>{this.state.show ? 'hide': 'show'}</button>    
            </div>
          )
        }
    }
    ReactDOM.render(<Change name=""/>,root)
</script>
</body>
</html>